package cn.hgpu.controller;

import cn.hgpu.domain.UserInfo;
import cn.hgpu.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/login")
    public String userLogin(UserInfo userInfo, HttpServletRequest request){
        //调用service
        UserInfo loginUser= userService.findUserByUnameAndUpsw(userInfo);
    //2.判断登录是否成功
        if(loginUser != null){
            // 将信息保存到session对象中
            HttpSession session = request.getSession();
            session.setAttribute("LOGIN_USER",loginUser);

            return "main";
        }
            request.setAttribute("msg","用户名或密码错误!!");

            return "login";

    }
}
